import axios from "axios";

const crossURL = import.meta.env.VITE_DEV_CROSS_URL;
// 创建axios实例
const http = axios.create({
  baseURL: crossURL,
  timeout: 5000,
});

// axios请求拦截器
http.interceptors.request.use(
  (config) => {
    // 统一设置 Content-Type
    config.headers["Content-Type"] = "application/json";
    return config;
  },
  (e) => Promise.reject(e)
);

// axios响应式拦截器
http.interceptors.response.use(
  (res) => res.data,
  (e) => {
    return Promise.reject(e);
  }
);

export default http;
